package interpreter.debugger.ui;

import interpreter.debugger.DebugVirtualMachine;

/**
 * Clears break points
 * 
 * @author Kris Selbekk
 */
public class ClearBrkPtCommand extends Command {
    private boolean found;
    private int numCleared;

    public void init( DebugVirtualMachine dvm ) {
        super.init(dvm);
        found = true;
        numCleared = 0;
    }

    /**
     * Clears one or all breakpoints
     * @param args
     */
    public void exec( String[] args ) {
        if( args.length == 1) { // If no arguments, clear all breakpoints
            numCleared = dvm.clearBreakpoints();
            found = true;
        } else if( args.length == 2 ) {
            found = dvm.clearBreakpoint( Integer.parseInt(args[1]) );
            numCleared = 1;
        } else
            found = false;
        

    }
    public void print() {
        StringBuilder out = new StringBuilder();

        if( found && numCleared > 0 ) {
            if( numCleared == 1)
                out.append(numCleared + " breakpoint was removed.");
            else
                out.append(numCleared + " breakpoints were removed.");
        } else
            out.append("Could not find breakpoint(s).");

        System.out.println( out );
    }
}
